package com.wolfalpha.utron.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wolfalpha.utron.R;
import com.wolfalpha.utron.bean.ItemRequirement;
import com.wolfalpha.utron.utils.StringUtils;

import java.util.List;

/**
 * 需求列表适配器
 * <p/>
 * Created by luodon on 15/8/19.
 */
public class RequirementAdapter extends BaseAdapter {


    private LayoutInflater inflater;

    private List<ItemRequirement> requires;

    public RequirementAdapter(Context context, List<ItemRequirement> rs) {
        inflater = LayoutInflater.from(context);
        requires = rs;
    }

    @Override
    public int getCount() {
        return requires.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_rquirement, null);
            viewHolder = new ViewHolder();
            viewHolder.tvContent = (TextView) convertView.findViewById(R.id.i_tv_requirement_content);
            viewHolder.tvTime = (TextView) convertView.findViewById(R.id.i_tv_requirement_time);
            viewHolder.tvTotal = (TextView) convertView.findViewById(R.id.i_tv_requirement_total);
            viewHolder.tvYes = (TextView) convertView.findViewById(R.id.i_tv_requirement_yes);
            viewHolder.tvNo = (TextView) convertView.findViewById(R.id.i_tv_requirement_no);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        //设置控件内容
        viewHolder.tvContent.setText(requires.get(position).getContent());
        viewHolder.tvTotal.setText(String.valueOf(requires.get(position).getTotal()));
        viewHolder.tvTime.setText(StringUtils.friendly_time(StringUtils.TimeStamp2Date(requires.get(position).getTime() * 1000)));
        viewHolder.tvYes.setText(String.valueOf(requires.get(position).getYes()));
        viewHolder.tvNo.setText(String.valueOf(requires.get(position).getNo()));

        return convertView;
    }

    /**
     * 控件
     */
    class ViewHolder {
        private TextView tvContent;
        private TextView tvTime;
        private TextView tvTotal;
        private TextView tvYes;
        private TextView tvNo;
    }
}
